<!--
@license
Copyright 2021 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ng-container *ngIf="cardMetadata; else noCardMetadata">
  <h2>
    <ng-template #dataName>
      <ng-container [ngSwitch]="cardMetadata.plugin">
        <span *ngSwitchCase="PluginType.SCALARS">scalar</span>
        <span *ngSwitchCase="PluginType.HISTOGRAMS">histogram</span>
        <span *NgSwitchDefault>unknown</span>
      </ng-container>
    </ng-template>

    <span>Download&nbsp;</span
    ><ng-container *ngTemplateOutlet="dataName"></ng-container
    ><span>&nbsp;data for&nbsp;</span
    ><code class="tag-name" [title]="cardMetadata.tag"
      >{{cardMetadata.tag}}</code
    >
  </h2>

  <mat-dialog-content>
    <mat-form-field class="run-selector" appearance="fill">
      <mat-label>Select a run to download a data for a series</mat-label>
      <select
        matNativeControl
        name="run"
        cdkFocusInitial
        required
        [value]="selectedRunId || ''"
        (change)="runSelected.emit($event.target.value)"
      >
        <option selected [value]="''">-</option>
        <!-- There is no guarantee that the run.name is unique but run.id is.-->
        <option *ngFor="let run of runs" [value]="run.id">{{run.name}}</option>
      </select>
    </mat-form-field>

    <div class="download-controls">
      <span>Download as…</span>&nbsp;<a
        mat-stroked-button
        [disabled]="!downloadUrlJson"
        [download]="getDownloadName('json')"
        [attr.href]="downloadUrlJson"
        >JSON</a
      >
      <a
        mat-stroked-button
        [disabled]="!downloadUrlCsv"
        [download]="getDownloadName('csv')"
        [attr.href]="downloadUrlCsv"
        >CSV</a
      >
    </div>
  </mat-dialog-content>

  <mat-dialog-actions align="end">
    <button mat-button mat-dialog-close>Close</button>
  </mat-dialog-actions>
</ng-container>

<ng-template #noCardMetadata>Loading...</ng-template>
